﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CdcSoftware.Pivotal.Engine.Client.ClientTasks.Attributes;
using CdcSoftware.Pivotal.Engine.Client.Services.Interfaces;
using System.Collections;
using System.Data;
using System.Windows.Forms;
using CdcSoftware.Pivotal.Engine.UI.DataTypes.FormParams;
using CdcSoftware.Pivotal.Engine;
using CdcSoftware.Pivotal.Engine.Client.Types;
using CdcSoftware.Pivotal.Engine.ServerProxy;
using CdcSoftware.Pivotal.Engine.Types.DataTemplates;
using CdcSoftware.Pivotal.Engine.Types.Database;
using CdcSoftware.Pivotal.Engine.Types.Localization;
using CdcSoftware.Pivotal.Engine.Types.ServerTasks;
using CdcSoftware.Pivotal.Engine.UI;
using CdcSoftware.Pivotal.Engine.UI.Forms;
using CdcSoftware.Pivotal.Applications.Core.Client;
using CdcSoftware.Pivotal.Applications.Core.Common;
using CdcSoftware.Pivotal.Engine.UI.DataTypes.Searches;
using CdcSoftware.Pivotal.Applications.Core.Data.Element;

namespace Pcm.Retail.Client.FormTasks
{
    public class ProductCommandClientTask : CommandClientTask
    {
        [ClientTaskCommand]
        public virtual void ShowProductClassification()
        {
            try
            {
                DataTable dataTable = Globals.GetDataTable(SystemTable.Name, new string[] { });
                if (dataTable != null && dataTable.Rows.Count > 0)
                {
                    Id systemId = Id.Create(dataTable.Rows[0][SystemTable.Field.SystemId]);
                    IActionService actionService = ClientContext.ClientAPIService.GetService<IActionService>();
                    IFormActionTarget actionTarget = actionService.CreateActionTarget<IFormActionTarget>();
                    actionTarget.Table = SystemTable.Name;
                    actionTarget.Form = "RE_Product_Classification";
                    actionTarget.RecordId = systemId;
                    actionService.ExecuteActionTarget(actionTarget, ActionCommand.Show);
                }
            }
            catch (Exception exc)
            {
                Globals.HandleException(exc, true);
            }
        }
    }
}
